<template>
  <!--<el-form :model="queryParams" ref="queryRef" :inline="true" label-width="120px">
    <el-form-item label="评估记录编号" prop="assessCode">
      <el-input v-model="queryParams.assessCode" clearable></el-input>
    </el-form-item>
    <el-form-item label="评估记录名称" prop="assessName">
      <el-input v-model="queryParams.assessName" clearable></el-input>
    </el-form-item>
    <el-form-item label=" ">
      <el-button type="primary" @click="handleQuery">查询</el-button>
      <el-button @click="resetQuery">重置</el-button>
    </el-form-item>
  </el-form>-->

  <el-table v-loading="loading" ref="tableRef" :data="dataList" :row-key="getRowKeys" stripe @selection-change="handleSelectionChange">
    <el-table-column type="selection" width="55" align="center" :reserve-selection="true" />
    <el-table-column label="评估记录编号" prop="assessCode" align="center" />
    <el-table-column label="评估记录名称" prop="assessName" align="center" />
    <el-table-column label="房屋基础数据" prop="houseDataFlag" align="center">
      <template #default="{row}">
        <span>{{ houseBasicData.find(item => item.value == row.houseDataFlag)?.name }}</span>
      </template>
    </el-table-column>
    <el-table-column label="评估区域" prop="" align="center">
      <template #default="{row}">
        <p v-for="item in row.list" :key="item.id" v-if="row.list">{{ `${item.ppName}-${item.cityName}-${item.name}` }}</p>  
        <p v-else>{{ row.coordinateRange }}</p>
      </template>
    </el-table-column>
    <el-table-column label="地震输入方式" prop="seismicInputMode" align="center">
      <template #default="{row}">
        <span>{{ inputMethods(props.type).find(item => item.value === row.seismicInputMode)?.name }}</span>
      </template>
    </el-table-column>
    <el-table-column label="评估描述" prop="assessDesc" align="center" />
<!--    <el-table-column label="创建单位" prop="company" align="center" />-->
<!--    <el-table-column label="创建人" prop="createUser" align="center" />-->
  </el-table>

  <!--<pagination style="margin-top: 15px" v-show="queryParams.total > 0" :total="queryParams.total"
    v-model:page="queryParams.page" v-model:limit="queryParams.rows" @pagination="getList" ref="pagination" />-->

  <div style="text-align: center;margin-top: 20px;">
    <el-button type="primary" @click="submitSelect">确定</el-button>
  </div>
</template>
<script setup name="seismicAssess">
import { inputMethods, houseBasicData } from '@/views/building/index'
import { getAssessByParam } from '@/api/buildingRiskZoning/singleRiskZonation/index'

const props = defineProps({
  open: Boolean,
  estimateObj: String,
  houseDataFlag: String,
  seismicInputMode: String,
  type: String
})
const emits = defineEmits(['getSelectData'])
const { proxy } = getCurrentInstance()

const queryParams = ref({
  // page: 1,
  // rows: 10,
  // total: 0,
  estimateObj:"3",//1、抗震能力；2、人员伤亡；3、经济损失
  houseDataFlag:"1",//0、房屋单体数据；1、房屋网格数据
  seismicInputMode:"0",//0、烈度；1、4个概率水准；2、地震影响场
})
const loading = ref(false)
const dataList = ref([])
const ids = ref([]);
const selectData = ref([]);

const getList = () => {
  loading.value = true;
  getAssessByParam({...queryParams.value}).then(res => {
    loading.value = false
    dataList.value = res.data;
  })
}
// 查询
const handleQuery = () => {
  getList()
}

// 重置
const resetQuery = () => {
  proxy.resetForm('queryRef')
  queryParams.value.page = 1
  handleQuery()
}

function getRowKeys(row) {//记录每行的key值
  return row.id;//id 自己查看 row 里的数据
}

// 多选框选中数据
function handleSelectionChange(selection) {
  ids.value = selection.map(item => item.id);
  selectData.value = selection;
}

//确定选择
function submitSelect(){
  emits('getSelectData', selectData.value);
}

onMounted(() => {
  queryParams.value.estimateObj = props.estimateObj;//评估对象 1、抗震能力；2、人员伤亡；3、经济损失
  queryParams.value.houseDataFlag = props.houseDataFlag;//选择房屋基础数据 0、房屋单体数据；1、房屋网格数据
  queryParams.value.seismicInputMode = props.seismicInputMode;//地震输入方式 0、烈度；1、4个概率水准；2、地震影响场
  getList();
})

/*onBeforeUnmount(() => {
  proxy.$Bus.all.clear()
})*/
</script>
<style scoped></style>